package com.yunhe.java.Day11;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
/**
 * Created by Administrator on 2017/8/4 0004.
 */public class collection {
    public static void main(String[] args) {
        int [] arr={1,2,3};
        List list =new ArrayList();
        list.add('c');
        list.add("汉字");
        list.add("good");
        list.add(new Person("王",22,500.0));
        System.out.println("集合长度："+list.size());
        list.remove("good");
        for(Object o:list){
            System.out.print(o+" ");}//for循环遍历集合
        Iterator itr= list.iterator();//iterator 迭代器遍历集合
        while (itr.hasNext()){
            System.out.print(itr.next()+" ");}
        Object []  obj1=list.toArray();//以数组的形式打印
        System.out.println(Arrays.toString(obj1));
        System.out.println(list.hashCode());//打印hashcode码
        List list1=new ArrayList();
        list1.add(arr [2]);
        list1.add('c');
        list1.add("汉字");
        list1.add(new Person("李",22,500.0));
        list1.retainAll(list);  System.out.println(list1);//求交集，即取两个集合共有元素并打印
        list.removeAll(list1); System.out.println(list);//清除list集合中所有list1集合中的元素并打印
        list.addAll(1,list1); System.out.println(list);//在指定位置插入list1并打印//
       }
 }
